<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>话术后台管理系统</title>
<style>
body {
	background: #ebebeb;
	font-family: "helvetica neue", "hiragino sans gb", "microsoft yahei",
		"\9ed1\4f53", arial, sans-serif;
	color: #222;
	font-size: 12px;
}

* {
	padding: 0px;
	margin: 0px;
}

.top_div {
	background: #008ead;
	width: 100%;
	height: 350px;
}

.ipt {
	border: 1px solid #d3d3d3;
	padding: 10px 10px;
	width: 290px;
	border-radius: 4px;
	padding-left: 35px;
	-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
	box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
	-webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow
		ease-in-out .15s;
	-o-transition: border-color ease-in-out .15s, box-shadow ease-in-out
		.15s;
	transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s
}

.ipt:focus {
	border-color: #66afe9;
	outline: 0;
	-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px
		rgba(102, 175, 233, .6);
	box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px
		rgba(102, 175, 233, .6)
}

.u_logo {
	background:
		url("/static/images/username.png")
		no-repeat;
	padding: 10px 10px;
	position: absolute;
	top: 43px;
	left: 40px;
}

.p_logo {
	background:
		url("/static/images/password.png")
		no-repeat;
	padding: 10px 10px;
	position: absolute;
	top: 12px;
	left: 40px;
}

a {
	text-decoration: none;
}

.tou {
	background:
		url("/static/images/tou.png")
		no-repeat;
	width: 97px;
	height: 92px;
	position: absolute;
	top: -87px;
	left: 140px;
}

.left_hand {
	background:
		url("/static/images/left_hand.png")
		no-repeat;
	width: 32px;
	height: 37px;
	position: absolute;
	top: -38px;
	left: 150px;
}

.right_hand {
	background:
		url("/static/images/right_hand.png")
		no-repeat;
	width: 32px;
	height: 37px;
	position: absolute;
	top: -38px;
	right: -64px;
}

.initial_left_hand {
	background:
		url("/static/images/hand.png")
		no-repeat;
	width: 30px;
	height: 20px;
	position: absolute;
	top: -12px;
	left: 100px;
}

.initial_right_hand {
	background:
		url("/static/images/hand.png")
		no-repeat;
	width: 30px;
	height: 20px;
	position: absolute;
	top: -12px;
	right: -112px;
}

.left_handing {
	background:
		url("/static/images/left-handing.png")
		no-repeat;
	width: 30px;
	height: 20px;
	position: absolute;
	top: -24px;
	left: 139px;
}

.right_handinging {
	background:
		url("/static/images/right_handing.png")
		no-repeat;
	width: 30px;
	height: 20px;
	position: absolute;
	top: -21px;
	left: 210px;
}
</style>


</head>
<body>
	<div class="top_div"></div>
		<div
			style="background: rgb(255, 255, 255); margin: -100px auto auto; border: 1px solid rgb(231, 231, 231); border-image: none; width: 400px; height: 260px; text-align: center;">
			<div style="width: 165px; height: 96px; position: absolute;">
				<div class="tou"></div>
				<div class="initial_left_hand" id="left_hand"></div>
				<div class="initial_right_hand" id="right_hand"></div>
			</div>
			<h2 style="margin-top: 16px">后台管理系统</h2>

			<p style="padding: 30px 0px 10px; position: relative;">
				<span class="u_logo"></span>
				<input id="username" name="username" class="ipt" type="text"
					placeholder="请输入用户名">
			</p>
			<p style="position: relative;">
				<span class="p_logo"></span>
				<input id="password" name="password" class="ipt" type="password"
					placeholder="请输入密码" >
			</p>
			<div
				style="height: 50px; line-height: 50px; margin-top: 30px; border-top-color: rgb(231, 231, 231); border-top-width: 1px; border-top-style: solid;">
						<input type="submit" id="submitBtn"
						style="background: rgb(0, 142, 173); padding: 7px 16px; border-radius: 4px; border: 1px solid rgb(26, 117, 152); border-image: none; color: rgb(255, 255, 255); font-weight: bold;margin-top: 10px"
						value="登录" />
				<div style="margin-top: -10px"><font color="red" id="error" ></font></div>

			</div>
		</div>
	<script src="http://tv.speechb.com/lib/bootstrap3/js/jquery-1.11.2.min.js"></script>
	<script type="text/javascript">
		$(function() {
			//得到焦点
			$("#password").focus(function() {

				$("#left_hand").animate({
					left : "150",
					top : " -38"
				}, {
					step : function() {
						if (parseInt($("#left_hand").css("left")) > 140) {
							$("#left_hand").attr("class", "left_hand");
						}
					}
				}, 2000);
				$("#right_hand").animate({
					right : "-64",
					top : "-38px"
				}, {
					step : function() {
						if (parseInt($("#right_hand").css("right")) > -70) {
							$("#right_hand").attr("class", "right_hand");
						}
					}
				}, 2000);
			});
			//失去焦点
			$("#password").blur(function() {
				$("#left_hand").attr("class", "initial_left_hand");
				$("#left_hand").attr("style", "left:100px;top:-12px;");
				$("#right_hand").attr("class", "initial_right_hand");
				$("#right_hand").attr("style", "right:-112px;top:-12px");
			});

			$("#submitBtn").click(function () {
				var username = $("#username").val();
				var password = $("#password").val();
				if (username == null || username == "") {
					$("#error").html("用户名不能为空！");
					return false;
				}
				if (password == null || password == "") {
					$("#error").html("密码不能为空！");
					return false;
				}
				$.ajax({
					//请求方式
					type : "POST",
					//请求地址
					url : "/admin/login_check",
					//数据，json字符串
					data : {
						"username":username,
						"password":password
					},
					//请求成功
					success : function(result) {
						if(result.code==1) {
							localStorage.setItem("username",username);
							localStorage.setItem("password",password);
							var lastUrl = document.referrer;
							// 登录界面不能跳转到本业
							if(lastUrl != null && lastUrl != "" && lastUrl.search("/admin/login") == -1 ) {
								window.location.href = lastUrl;
							} else {
								window.location.href = "/admin";
							}
						} else {
							$("#error").html("用户名或密码错误");
						}

						console.log(result);
					},
					//请求失败，包含具体的错误信息
					error : function(e){
						$("#error").html("操作失败！");
						console.log(e.responseText);
					}
				});

			});
			document.onkeydown=function(event){
				if (event.keyCode == 13) {
					$("#submitBtn").click();
				}
			}
			//判断字符是否为空的方法
			function isEmpty(obj){
				if(typeof obj == "undefined" || obj == null || obj == ""){
					return true;
				}else{
					return false;
				}
			}
			function initUserInfo() {
				var username = localStorage.getItem("username");
				if (!isEmpty(username)) {
				   $("#username").val(username)
					var password = localStorage.getItem("password");
				   if(!isEmpty(password)) {
					   $("#password").val(password);
				   }
			    }
			}
			initUserInfo();
		});
	</script>
</body>
</html>